﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;

namespace ShareTools
{
    public delegate void writeLog(string data);
    /// <summary>
    /// form类，用来操作界面，与页面交互，启动时，要读取初始化文件
    /// </summary>
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //生成远程地址
            string remoteIp = textBox2.Text;
            string remotePath = "\\\\"+remoteIp +"\\";
            string userName = "HDMA-4000";
            string passWord = "hdp";

            REMOTEDIRECTORY rd1 = new REMOTEDIRECTORY();
            rd1.MapDriveECS(remotePath ,userName ,passWord );
            string[] directoryInfo = rd1.ReadRemoteDirectory(remotePath +"playlist"+"\\");
            //MessageBox.Show(directoryInfo [0]);

            string exePath = System.Windows.Forms.Application.StartupPath;
            string ffmpegExePath = exePath + "\\resource\\ffmpeg.exe";
            string[,] mediaInfo = new String[10,2];
            int count = 0;
            foreach (string i in directoryInfo)
            {
                string tmp = i;
                //取出所有的.m2p文件
                if(!(tmp .IndexOf (".m2p")==-1))
                {
                    mediaInfo[count,0] = tmp;
                    FFMPEG ffmpeg = new FFMPEG();
                    ffmpeg.callFFMPEG(ffmpegExePath,mediaInfo [count ,0]);
                    string singleMeidaInfo = ffmpeg.mediaInfo;

                    StringDealWith sdw1 = new StringDealWith();
                    
                    mediaInfo[count, 1] = sdw1 .GetSubString( singleMeidaInfo,"Duration",18);
                    //MessageBox.Show(mediaInfo [count ,1]);
                    count++;
                }
            }
            count = 0;
            //2011-08-25 14:48 取出了所有的媒体文件
            //2011-08-25 16:53 已经将所有信息存入字符串。
            string [] mediaInfoFile = new  string [10];

            for (int i = 0; i < 10;i++ )
            {
                mediaInfoFile[i] = mediaInfo[i,0]+"      "+mediaInfo [i,1];
            }
            //test
            //2011-08-25 17:35 将info存在一个文件夹中去
            //MessageBox.Show(exePath );
            rd1.UploadTxtFile(exePath +"\\resource\\content.txt",mediaInfoFile);
            //2011-08-25 19:15 已经将content文件存入目标文件夹了，下面需要做的是如何生成播放列表
        }
        //用来操作schedule
        private void button2_Click(object sender, EventArgs e)
        {
            schedule form2 = new schedule();
            form2.Show();
        }
        /// <summary>
        /// 显示远程链接页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            remoteConnect rc = new remoteConnect(new writeLog(Writelog));
            rc.Show();
        }
        /// <summary>
        /// 写日志函数，用来被委托调用
        /// </summary>
        /// <param name="data"></param>
        public void Writelog(string data)
        {
            this .textBox1.Text = data  ;
        }
    }
}
